#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void helper(int* arr, int length) {
    int max = arr[0], sum = 0;
    for (int pos = 0; pos < length; pos++) {
        if (sum + arr[pos] < 0) {
            while (pos + 1 < length && arr[pos] < 0) {
                pos++;
            }
            if (pos < length) {
                sum = arr[pos];
            }
        } else {
            sum += arr[pos];
        }
        if (max < sum) {
            max = sum;
        }
    }
    printf("%d\n", max);
}

int main() {
    int* arr;
    int length;
    FILE* fp = fopen("./data.in", "r");
    while (fscanf(fp, "%d\n", &length) != EOF) {
        arr = (int*)malloc(length * sizeof(int));
        for (int i = 0; i < length; i++) {
            fscanf(fp, "%d", &arr[i]);
        }
        helper(arr, length);
    }
}